__author__ = 'zhanpeng'
import json
from aliyunsdkcore import client
from aliyunsdkecs.request.v20140526 import DescribeSecurityGroupAttributeRequest
from aliyunsdkecs.request.v20140526 import RevokeSecurityGroupRequest
from aliyunsdkecs.request.v20140526 import AuthorizeSecurityGroupRequest
from aliyunsdkecs.request.v20140526 import DescribeImagesRequest
from aliyunsdkecs.request.v20140526 import DescribeInstancesRequest

def describeSecurityGroupAttributeRequest():
        request = DescribeSecurityGroupAttributeRequest.DescribeSecurityGroupAttributeRequest()
        request.set_SecurityGroupId('sg-2872p4xdv')
        request.set_accept_format('json')
        return request

def revokeSecurityGroupRequest():
        request = RevokeSecurityGroupRequest.RevokeSecurityGroupRequest()
        request.set_SecurityGroupId('sg-2872p4xdv')
        request.set_IpProtocol('all')
        request.set_PortRange('-1/-1')
        request.set_SourceCidrIp('0.0.0.0/0')
        request.set_Policy('accept')
        request.set_accept_format('json')
        return request

def authorizeSecurityGroupRequest():
        request = AuthorizeSecurityGroupRequest.AuthorizeSecurityGroupRequest()
        request.set_SecurityGroupId('sg-2872p4xdv')
        request.set_IpProtocol('all')
        request.set_PortRange('-1/-1')
        request.set_SourceCidrIp('0.0.0.0/0')
        request.set_Policy('accept')
        request.set_accept_format('json')
        return request

def imageRequest():
        request = DescribeImagesRequest.DescribeImagesRequest()
        request.set_accept_format('json')
        return request

if __name__ == '__main__':
    access_key_id = '3iUyMBmMcX7hI9Ae'
    access_key_secret = 'wcWDxxujAIZi6keAXkgUvthtZH2c8j'
    region_id = 'cn-qingdao'
    acs_client = client.AcsClient(access_key_id,access_key_secret,region_id)
#    request = revokeSecurityGroupRequest()
    request = DescribeInstancesRequest.DescribeInstancesRequest()
    request.set_accept_format('json')
    print type(request)
    result = acs_client.do_action(request)
    # json_result = json.load(result)
    print(result)
    # print json